function setupBtnTapped(domId){
	mui('#'+domId).on('tap','.toExamBtn',toExam)
	mui('#'+domId).on('tap','.mui-icon-arrowright',toExam)
	mui('#'+domId).on('tap','.packup',packupTapped)
	mui('#'+domId).on('tap','.secondCell .nur-triangleup',triangleupTapped)
}
function clearBtnTapped(domId){
	mui('#'+domId).off('tap','.toExamBtn',toExam)
	mui('#'+domId).off('tap','.mui-icon-arrowright',toExam)
	mui('#'+domId).off('tap','.packup',packupTapped)
	mui('#'+domId).off('tap','.secondCell .nur-triangleup',triangleupTapped)
}

function packupTapped(){
	var liDom = this.parentNode.parentNode
	if (liDom.getAttribute('class').indexOf('dhc-active') != -1) {
		liDom.classList.remove('dhc-active');
	}else{
		liDom.classList.add('dhc-active');
	}
}

function triangleupTapped(){
	var secondCell = this.parentNode.parentNode.parentNode
	if (secondCell.getAttribute('class').indexOf('dhc-active') != -1) {
		secondCell.classList.remove('dhc-active');
	}else{
		secondCell.classList.add('dhc-active');
	}
}
function getOneChildrenHtml(oneData,firstIndex,secondIndex,sliderIndex){
	var errNum = parseInt(oneData['ErrorNum']==""?0:oneData['ErrorNum'])
	var answerNum = parseInt(oneData['AnswerNum'])
	var errRate = 0
	if (answerNum != 0) {
		errRate = errNum/answerNum * 100
	}
	var children = oneData['children']
	var childAngle = '<div class="nurfont nur-triangleup"></div>'
	if (!children || children.length == 0) {
		childAngle = ''
	}
	var html = '<div class="secondCell">'+
		'<div class="titleArea">'+
			'<div class="classTitle">'+oneData['TheoryDesc']+childAngle+'</div>'+
			'<div class="classSubInfo">总题数：'+oneData['AllNum']+' | 已练习题数：'+oneData['AnswerNum']+' | 错题率：'+errRate+'%</div>'+
			'<div class="mui-icon mui-icon-arrowright" data-rw="'+oneData['rw']+'" data-page="'+sliderIndex+'" data-index="'+firstIndex +'-' + secondIndex +'"></div>'+
		'</div>'
	if (childAngle == '') {
		return html +'</div>'
	}
	for (var i = 0; i < children.length;i++) {
		var oneChild = children[i]
		var errNum = parseInt(oneChild['ErrorNum'])
		var answerNum = parseInt(oneChild['AnswerNum'])
		var errRate = 0
		if (answerNum != 0) {
			errRate = errNum/answerNum * 100
		}
		html += '<div class="thirdCell">'+
			'<div class="classTitle">'+oneChild['TheoryDesc']+'</div>'+
			'<div class="classSubInfo">总题数：'+oneChild['AllNum']+' | 已练习题数：'+oneChild['AnswerNum']+' | 错题率：'+errRate+'%</div>'+
			'<div class="mui-icon mui-icon-arrowright" data-rw="'+oneChild['rw']+'" data-page="'+sliderIndex+'" data-index="'+firstIndex +'-' + secondIndex +'-'+i +'"></div>'+
		'</div>'
	}
	return html + '</div>'
}
	
function updateExamUI(dataArr,domId,sliderIndex){
	if (sliderIndex == undefined) {
		sliderIndex = ''
	}
	var ulDom = document.getElementById(domId);
	for(var i = 0; i < dataArr.length; i++){
		var oneData = dataArr[i]
		var children = oneData['children']
		var childAngle = '<div class="nurfont nur-triangleup packup"></div>'
		if (!children || children.length == 0) {
			childAngle = ''
		}
		var errNum = parseInt(oneData['ErrorNum']==""?0:oneData['ErrorNum'])
		var answerNum = parseInt(oneData['AnswerNum'])
		var errRate = 0
		if (answerNum != 0) {
			errRate = errNum/answerNum * 100
		}
		var html = '<div class="titleArea">'+
			'<div class="classTitle">'+oneData['TheoryDesc']+'</div>'+
			'<div class="classSubInfo">总题数：'+oneData['AllNum']+' | 已练习题数：'+oneData['AnswerNum']+' | 错题率：'+errRate+'%</div>'+ childAngle +
			'<div class="mui-btn mui-bg-primary baseBtn toExamBtn" data-rw="'+oneData['rw']+'" data-page="'+sliderIndex+'" data-index="'+i+'">去练习</div>'+
		'</div>';
		if (childAngle != '') {
			for (var j = 0; j < children.length;j++) {
				var oneHtml = getOneChildrenHtml(children[j],i,sliderIndex)
				html += oneHtml
			}
		}
		var newLi = document.createElement('li')
		ulDom.appendChild(newLi)
		newLi.setAttribute('class','mui-table-view-cell')
		newLi.innerHTML = html
	}
}
